home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <limits.h>
- #include <math.h>
-
- #define Arand INT_MAX /* rand() returns values between 0 and Arand */
-
- SHORT Nrand; /* the # of samples of rand() to be taken in Gauss() */
- double GaussAdd; /* real parameter for linear transformation in Gauss() */
- double GaussFac; /* ditto */
-
- /* InitGauss() will initialize the Random Gauss routine */
- void InitGauss(seed)
- unsigned int seed;
- {
- Nrand = 4;
- GaussAdd = sqrt((double)(3.0 * Nrand));
- GaussFac = (double)2.0 * GaussAdd / ((double)Nrand * (double)Arand);
- srand((unsigned)seed);
- }
-
- /* Gauss() will return a Gaussian random number */
- double Gauss(void)
- {
- double sum,c;
- SHORT i;
-
- sum = 0.0;
- for(i=0;i<Nrand;i++)
- sum += (double)rand();
- c = GaussFac * sum - GaussAdd;
- return(c);
- }